package com.xbongbong.saas.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.enums.FieldTypeEnum;
import com.xbongbong.saas.enums.business.ProductEnum;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @author haibin.zhang
 * @version v1.0
 * @date 2019/8/27 10:54
 * @since v1.0
 * data内外都有的数据，es里以data外为准，因为迁移过来的没有data内的数据
 * @see com.xbongbong.saas.enums.subform.ContractProductSubFormEnum
 */
@Getter
public enum SelectProductEnum {
    //新建编辑显示
    PRODUCT("text_1","product","enum.selectProduct.attrName.product",FieldTypeEnum.LINK_DATA.getType(),0,""),
    PRODUCT_NAME("productName","productName","enum.selectProduct.attrName.product_name",FieldTypeEnum.TEXT.getType(),0,ProductEnum.NAME.getAttr()),
    PRODUCT_NO("productNo","productNo","enum.selectProduct.attrName.product_no",FieldTypeEnum.TEXT.getType(),0,ProductEnum.PRODUCT_NO.getAttr()),
    SPECIFICATION("specification","specification","enum.selectProduct.attrName.specification",FieldTypeEnum.TEXT.getType(),0,ProductEnum.SPECIFICATION_LINK_TEXT.getAttr()),
    BARCODE("barcode","barcode","enum.selectProduct.attrName.barcode",FieldTypeEnum.TEXT.getType(),0,ProductEnum.BARCODE.getAttr()),
    PRICE("num_1","price","enum.selectProduct.attrName.price",FieldTypeEnum.NUM.getType(),0,ProductEnum.PRICE.getAttr()),
    DISCOUNT("num_4","discount","enum.selectProduct.attrName.discount",FieldTypeEnum.NUM.getType(),1,""),
    SELLING_PRICE("num_6","sellingPrice","enum.selectProduct.attrName.selling_price",FieldTypeEnum.NUM.getType(),1,""),
    NUM("num_3","num","enum.selectProduct.attrName.num",FieldTypeEnum.NUM.getType(),1,""),
    MEMO("text_3","memo","enum.selectProduct.attrName.memo",FieldTypeEnum.TEXTAREA.getType(),1,""),
    UNIT("text_8","unit","enum.selectProduct.attrName.unit",FieldTypeEnum.COMBO.getType(),0,ProductEnum.UNIT.getAttr()),
    STOCK("num_12","stock","enum.selectProduct.attrName.stock",FieldTypeEnum.NUM.getType(),0,ProductEnum.STOCK.getAttr()),
    SUBTOTAL("num_5","subTotal","enum.selectProduct.attrName.subtotal",FieldTypeEnum.NUM.getType(),0,""),
    COST("num_2","cost","enum.selectProduct.attrName.cost",FieldTypeEnum.NUM.getType(),0,ProductEnum.COST.getAttr()),
    TOTAL_COST("num_7","totalCost","enum.selectProduct.attrName.total_cost",FieldTypeEnum.NUM.getType(),0,""),
    //批次管理字段
    BATCH("text_5","batch","enum.selectProduct.attrName.batch",FieldTypeEnum.BATCH.getType(),1,""),
    PRODUCE_DATE("num_8","productDate","enum.selectProduct.attrName.produce_date",FieldTypeEnum.DATETIME.getType(),1,""),
    GUARANTEE_PERIOD("num_9","guaranteePeriod","enum.selectProduct.attrName.guarantee_period",FieldTypeEnum.NUM.getType(),1,""),
    EXPIRE_DATE("num_40","expireDate","enum.selectProduct.attrName.expire_date",FieldTypeEnum.DATETIME.getType(),1,""),
    WAREHOUSE("text_6","warehouse","enum.selectProduct.attrName.warehouse",FieldTypeEnum.LINK_BUSINESS_SINGLE.getType(),1,""),
    //退货相关专属,对应的出入库单
    SOURCE_DOC("text_10","sourceDoc","enum.selectProduct.attrName.source_doc",FieldTypeEnum.TEXT.getType(),1,""),
    //盘点单专属
    INVENTORY("text_11","inventory","enum.selectProduct.attrName.inventory",FieldTypeEnum.TEXT.getType(),1,""),
    //bom单、生产单专属
    LOSS_RATE("num_11","lossRate","enum.selectProduct.attrName.loss_rate",FieldTypeEnum.NUM.getType(),1,""),
    //部分功能提前考虑，防一手卡特毒打
    //序列号
    //库位

    //新建编辑隐藏，详情展示
    INSTOCK_NUM("num_17","inNum","enum.selectProduct.attrName.instock_num",FieldTypeEnum.NUM.getType(),1,""),
    OUTSTOCK_NUM("num_13","outNum","enum.selectProduct.attrName.outstock_num",FieldTypeEnum.NUM.getType(),1,""),
    WAIT_INSTOCK_NUM("num_14","waitInNum","enum.selectProduct.attrName.wait_instock_num",FieldTypeEnum.NUM.getType(),1,""),
    WAIT_OUTSTOCK_NUM("num_15","waitOutNum","enum.selectProduct.attrName.wait_outstock_num",FieldTypeEnum.NUM.getType(),1,""),
    RETURN_NUM("num_16","returnNum","enum.selectProduct.attrName.return_num",FieldTypeEnum.NUM.getType(),1,""),
    OUT_OF_STOCK("num_18","outOfStock","enum.selectProduct.attrName.out_of_stock",FieldTypeEnum.NUM.getType(),1,""),
    CONTRACT_STATUS("text_9","contractStatus","enum.selectProduct.attrName.contract_status",FieldTypeEnum.TEXT.getType(),1,""),
    DETAIL_STATUS("text_20","detailStatus","enum.selectProduct.attrName.detail_status",FieldTypeEnum.TEXT.getType(),1,""),
    SHIPMENTS_NUM("num_51","shipmentsNum","enum.selectProduct.attrName.shipments_num",FieldTypeEnum.NUM.getType(),0,""),
    PROMOTION("text_21","promotion","enum.selectProduct.attrName.promotion",FieldTypeEnum.TEXT.getType(),0,""),

    //SELL_TOTAL("num_19","sellTotal","产品售价合计",FieldTypeEnum.NUM.getType(),0,""),


    // text_22 在采购合同产品中已使用
    SOURCE_SOURCE_DOC("text_71","sourceDoc","enum.selectProduct.attrName.source_source_doc",FieldTypeEnum.TEXT.getType(),1,""),
    SOURCE_PRICE("num_41","price","enum.selectProduct.attrName.source_price",FieldTypeEnum.NUM.getType(),0,ProductEnum.PRICE.getAttr()),
    SOURCE_BATCH("text_72","batch","enum.selectProduct.attrName.source_batch",FieldTypeEnum.TEXT.getType(),1,""),
    SOURCE_PRODUCE_DATE("num_42","productDate","enum.selectProduct.attrName.source_produce_date",FieldTypeEnum.DATETIME.getType(),1,""),
    SOURCE_GUARANTEE_PERIOD("num_43","guaranteePeriod","enum.selectProduct.attrName.source_guarantee_period",FieldTypeEnum.NUM.getType(),1,""),
    SOURCE_MEMO("text_73","memo","enum.selectProduct.attrName.source_memo",FieldTypeEnum.TEXTAREA.getType(),1,""),
    BUSINESS_UNIT("num_44","businessUnit","enum.selectProduct.attrName.businessUnit",FieldTypeEnum.NUM.getType(),1,""),
    BUSINESS_NUM("num_45","businessNum","enum.selectProduct.attrName.businessNum",FieldTypeEnum.NUM.getType(),1,""),
    RATE("num_46","businessNum","enum.selectProduct.attrName.rate",FieldTypeEnum.NUM.getType(),1,""),
    UNIT_GROUP("num_47","unitGroup","enum.selectProduct.attrName.unitGroup",FieldTypeEnum.NUM.getType(),1,""),
    BUSINESS_SELLING_PRICE("num_48","businessSellingPrice","enum.selectProduct.attrName.businessSellingPrice",FieldTypeEnum.TEXT.getType(),1,""),
    BUSINESS_PRICE("num_49","businessPrice","enum.selectProduct.attrName.businessPrice",FieldTypeEnum.TEXT.getType(),1,""),
    BUSINESS_COST("num_50","businessCost","enum.selectProduct.attrName.businessCost",FieldTypeEnum.TEXT.getType(),1,""),
    BASIC_UNIT("basicUnit", "basicUnit","enum.selectProduct.attrName.source_basic_unit",FieldTypeEnum.TEXT.getType(),1,""),
    BASIC_UNIT_NUM("basicUnitNum","basicUnitNum","enum.selectProduct.attrName.source_basic_unit_num",FieldTypeEnum.NUM.getType(),1,""),


    //新建编辑显示
//    PRODUCT("product","关联产品",FieldTypeEnum.LINK_DATA.getType(),0,""),
//    PRODUCT_NAME("productName","产品名称",FieldTypeEnum.TEXT.getType(),0,ProductEnum.NAME.getAttr()),
//    PRODUCT_NO("productNo","产品编号",FieldTypeEnum.TEXT.getType(),0,ProductEnum.PRODUCT_NO.getAttr()),
//    SPECIFICATION("specification","规格",FieldTypeEnum.TEXT.getType(),0,ProductEnum.SPECIFICATION_LINK_TEXT.getAttr()),
//    BARCODE("barcode","条码",FieldTypeEnum.TEXT.getType(),0,ProductEnum.BARCODE.getAttr()),
//    PRICE("price","单价",FieldTypeEnum.NUM.getType(),0,ProductEnum.PRICE.getAttr()),
//    DISCOUNT("discount","折扣",FieldTypeEnum.NUM.getType(),1,""),
//    SELLING_PRICE("sellingPrice","售价",FieldTypeEnum.NUM.getType(),1,""),
//    NUM("num","数量",FieldTypeEnum.NUM.getType(),1,""),
//    MEMO("memo","备注",FieldTypeEnum.TEXT.getType(),1,""),
//    UNIT("unit","单位",FieldTypeEnum.COMBO.getType(),0,ProductEnum.UNIT.getAttr()),
//    STOCK("stock","库存数量",FieldTypeEnum.NUM.getType(),0,ProductEnum.STOCK.getAttr()),
//    SUBTOTAL("subTotal","小计",FieldTypeEnum.NUM.getType(),0,""),
//    COST("cost","成本",FieldTypeEnum.NUM.getType(),0,""),
//    TOTAL_COST("totalCost","成本小计",FieldTypeEnum.NUM.getType(),0,""),
//    //批次管理字段
//    PRODUCE_DATE("productDate","生产日期",FieldTypeEnum.DATETIME.getType(),1,""),
//    BATCH("batch","批次号",FieldTypeEnum.TEXT.getType(),1,""),
//    GUARANTEE_PERIOD("guaranteePeriod","保质期",FieldTypeEnum.NUM.getType(),1,""),
//    WAREHOUSE("warehouse","仓库",FieldTypeEnum.LINK_BUSINESS_SINGLE.getType(),1,""),
//    //退货相关专属,对应的出入库单
//    SOURCE_DOC("sourceDoc","源单单据",FieldTypeEnum.TEXT.getType(),1,""),
//    //盘点单专属
//    INVENTORY("inventory","盘亏盘盈",FieldTypeEnum.NUM.getType(),1,""),
//    //bom单、生产单专属
//    LOSS_RATE("lossRate","损耗率",FieldTypeEnum.NUM.getType(),1,""),
//    //部分功能提前考虑，防一手卡特毒打
//    //序列号
//    //库位
//
//    //新建编辑隐藏，详情展示
//    INSTOCK_NUM("inNum","已入数量",FieldTypeEnum.NUM.getType(),1,""),
//    OUTSTOCK_NUM("outNum","已出数量",FieldTypeEnum.NUM.getType(),1,""),
//    WAIT_INSTOCK_NUM("waitInNum","待入数量",FieldTypeEnum.NUM.getType(),1,""),
//    WAIT_OUTSTOCK_NUM("waitOutNum","待出数量",FieldTypeEnum.NUM.getType(),1,""),
//    RETURN_NUM("returnNum","退货数量",FieldTypeEnum.NUM.getType(),1,""),
//
//    PARENT_ID("parentId","spuId",FieldTypeEnum.NUM.getType(),1,""),
    UNKONW("unknow","","unknow",0,1,""),
    ;

    private String attr;

    private String saasAttr;

    private String attrName;

    private Integer fieldType;

    private Integer editable;

    private String productAttr;

    SelectProductEnum(String attr,String saasAttr, String attrName, Integer fieldType,Integer editable,String productAttr) {
        this.attr = attr;
        this.saasAttr = saasAttr;
        this.attrName = attrName;
        this.fieldType = fieldType;
        this.editable = editable;
        this.productAttr = productAttr;
    }

    public static String getAttrByProductAttr(String attr){
        for (SelectProductEnum selectProductEnum : SelectProductEnum.values()){
            if (Objects.equals(attr,selectProductEnum.getProductAttr())){
                return selectProductEnum.getAttr();
            }
        }
        return UNKONW.getAttr();
    }

    public static SelectProductEnum getAttrByAttr(String attr){
        for (SelectProductEnum selectProductEnum : SelectProductEnum.values()){
            if (Objects.equals(attr,selectProductEnum.getAttr())){
                return selectProductEnum;
            }
        }
        return UNKONW;
    }

    public static SelectProductEnum getAttrBySaasAttr(String saasAttr){
        for (SelectProductEnum selectProductEnum : SelectProductEnum.values()){
            if (Objects.equals(saasAttr,selectProductEnum.getSaasAttr())){
                return selectProductEnum;
            }
        }
        return UNKONW;
    }

    public static List<String> getAttrList() {
        List<String> attrList = new ArrayList<>();
        for (SelectProductEnum selectProductEnum : SelectProductEnum.values()){
            attrList.add(selectProductEnum.getAttr());
        }
        return attrList;
    }

    public static boolean ThousandBitsAttr(String attr) {
        return Objects.equals(attr,NUM.getAttr()) || Objects.equals(attr,SELLING_PRICE.getAttr()) || Objects.equals(attr,PRICE.getAttr())
                || Objects.equals(attr,STOCK.getAttr()) || Objects.equals(attr,COST.getAttr()) || Objects.equals(attr,TOTAL_COST.getAttr())
                || Objects.equals(attr,SUBTOTAL.getAttr()) || Objects.equals(attr,INSTOCK_NUM.getAttr()) || Objects.equals(attr,OUTSTOCK_NUM.getAttr())
                || Objects.equals(attr,WAIT_INSTOCK_NUM.getAttr()) || Objects.equals(attr,WAIT_OUTSTOCK_NUM.getAttr()) || Objects.equals(attr,RETURN_NUM.getAttr())
                || Objects.equals(attr,OUT_OF_STOCK.getAttr());
    }

    public String getAttrName() {
        return I18nMessageUtil.getMessage(attrName);
    }

    public String getI18nAttrName() {
        return attrName;
    }
}
